package algo.math.evaluator.context;

import algo.math.evaluator.context.operator.interfaces.IOperator;
import algo.math.evaluator.tokenizer.interfaces.IToken;
import algo.math.evaluator.tokenizer.interfaces.IToken.TokenType;

/**
 * Helper for the evaluation process
 */
public class Helper {
	
	private static Helper _helper;
	
	private Helper(){};
	
	/**
	 * Gets the helper.
	 *
	 * @return single instance of Helper
	 */
	public static Helper getInstance()
	{
		if (null==_helper)
		{
			_helper = new Helper();
		}
		return _helper;
	}
	
    /**
     * Checks if is open parenthesis.
     *
     */
    public  Boolean isOpenParenthesis(IToken token)
    {
        return (token.getType() == TokenType.OPERATOR && token.getValue()== "(");//getInstance().getOperator (OperatorSymbol.OPEN_PARENTHESIS.toString()).getValue());
    }

    /**
     * Checks if is close parenthesis.
     *
     */
    public  Boolean isCloseParenthesis(IToken token)
    {
    	return (token.getType() == TokenType.OPERATOR && token.getValue()== ")");
    }

    /**
     * Checks if is arithmetic operator.
     *
     */
    public  Boolean isArithmeticOperator(IToken token)
    {
    	return (token.getType() == TokenType.OPERATOR &&
    			!isCloseParenthesis(token) &&
    			!isOpenParenthesis(token) &&
    			 ((IOperator)token).getLevel()>=0
    			);
    }
}
